﻿using System.Diagnostics;

namespace Fujitsu.JiraAnalysis.Common
{
    public class EventLogger
    {
        private static EventLogger _instance;
        private IEventLog eventLog;

        private static object syncLock = new object();

        protected EventLogger(IEventLog _evenlog)
        {
            eventLog = _evenlog;
        }
        public static EventLogger CreateInstance(IEventLog _eventlog)
        {
            if (_instance == null)
            {
                lock (syncLock)
                {
                    if (_instance == null)
                    {
                        _instance = new EventLogger(_eventlog);
                    }
                }
            }
            else
            {
                _instance.eventLog = _eventlog;
            }

            return _instance;
        }

        private void LogWrite(string message, EventLogEntryType eventLogEntryType)
        {
            eventLog.WriteEntry(message, eventLogEntryType);
        }

        public void LogWrite(string message)
        {
            eventLog.WriteEntry(message, EventLogEntryType.Information);
        }

        public void LogWriteError(string message)
        {
            LogWrite(message, EventLogEntryType.Error);
        }

        public void LogWriteWarning(string message)
        {
            LogWrite(message, EventLogEntryType.Warning);
        }

        public void ClearLog() { eventLog.Clear(); }
    }
}
